<?
/*=====设置文件=====*/
/*===============*/

header("Access-Control-Allow-Origin:*");
//设置php输出页面为utf8
header("Content-type: text/html; charset=utf-8");
// 设置响应为JSON格式，编码UTF-8
header('Content-Type: application/json; charset=utf-8');

$user_id   = $_SERVER['HTTP_AUTHORIZATION'] ? : 0;
$_openid   = $_SERVER['HTTP_OPENID'] ? : 0;



$domain="https://milkorder.dagger.enpingshi.com";



//定义根目录文件路径
define('ROOT_PATH_', dirname(__FILE__));

if (!session_id()) session_start();

$is_weixin = 0;
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') == true){
	$is_weixin = 1;
}

$openid = isset($_SESSION['openid']) ? $_SESSION['openid'] : ''; //用户openid


if(isset($_REQUEST['type'] ) && isset($_REQUEST['order_id'] )){
    $_SESSION['share_order_id'] = $_REQUEST['order_id']; //记录推荐人

}

function getHeaders2()
{
    $header                = array();
    foreach ($_SERVER as $key => $value) {
        if ('HTTP_' == substr($key, 0, 5)) {
            $header[str_replace('_', '-', substr($key, 5))] = $value;
        }
        if (isset($_SERVER['PHP_AUTH_DIGEST'])) {
            $header['AUTHORIZATION'] = $_SERVER['PHP_AUTH_DIGEST'];
        } elseif (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
            $header['AUTHORIZATION'] = base64_encode($_SERVER['PHP_AUTH_USER'] . ':' . $_SERVER['PHP_AUTH_PW']);
        }
        if (isset($_SERVER['CONTENT_LENGTH'])) {
            $header['CONTENT-LENGTH'] = $_SERVER['CONTENT_LENGTH'];
        }
        if (isset($_SERVER['CONTENT_TYPE'])) {
            $header['CONTENT-TYPE'] = $_SERVER['CONTENT_TYPE'];
        }
    }
    return $header;
}
//设置绑定的域名
//include_once (ROOT_PATH_."/domain.php");


//当前域名
$host = $_SERVER['HTTP_HOST'];


//连接数据库
include_once (ROOT_PATH_."/connection.php");


//自动扫描function下文件，全部函数文件（.php）导入。
function listDir($dir)
{
    if(is_dir($dir))
    {
        if ($dh = opendir($dir))
        {
            while (($file = readdir($dh)) !== false)
            {
                if((is_dir($dir."/".$file)) && $file!="." && $file!="..")
                {
                    //echo "<b><font color='red'>文件名：</font></b>",$file,"<br><hr>";
                    listDir($dir."/".$file."/");
                }
                else
                {
                    if($file!="." && $file!="..")
                    {
                        //echo $file."<br>";
                    }
                }

                //判断是不是php文件，不是则不记录
                if(substr($file,-3)=="php"){$result[]=$file;};

            }
            closedir($dh);
        }
    }

    return $result;
}




$function_list=listDir(ROOT_PATH_."/function");


for($i=0;$i<count($function_list);$i++)
{

    include_once (ROOT_PATH_."/function/".$function_list[$i]);


}




 


if (defined('DEBUG_MODE') == false)
{
    define('DEBUG_MODE', 0);
}
/* 取得当前所在的根目录 */
define('ROOT_PATH', str_replace('config.php', '', str_replace('\\', '/', __FILE__)));

$now_system = 'wutongdao';

if($_SESSION['quanxian'] == 'all'){
	if(isset($_SESSION['system'])){
		$now_system = $_SESSION['system'] ;
	}

}

global $now_system;

$smarty = new cls_template;

$smarty->cache_lifetime = '3600';
$smarty->template_dir   = ROOT_PATH . 'controlbase' ;
$smarty->cache_dir      = ROOT_PATH . 'temp/caches';
$smarty->compile_dir    = ROOT_PATH . 'temp/compiled';

if ((DEBUG_MODE & 2) == 2)
{
        $smarty->direct_output = true;
        $smarty->force_compile = true;
}
 else
{
   $smarty->direct_output = false;
  $smarty->force_compile = false;
}

?>